<?php

class Bootstrap extends Zend_Application_Bootstrap_Bootstrap
{
    protected function _initDoctrine()
    {
        require dirname(__FILE__).'/../library/Doctrine.php';
        $config = $this->getOption('doctrine');

        $manager = Doctrine_Manager::getInstance();

        $manager->setAttribute(Doctrine_Core::ATTR_VALIDATE, Doctrine_Core::VALIDATE_ALL);
        //$manager->setAttribute(Doctrine_Core::ATTR_USE_DQL_CALLBACKS, true);
        $manager->setAttribute(Doctrine_Core::ATTR_AUTO_FREE_QUERY_OBJECTS, true);
        $manager->setAttribute(Doctrine_Core::ATTR_AUTO_ACCESSOR_OVERRIDE, true);
        $manager->setAttribute(Doctrine_Core::ATTR_AUTOLOAD_TABLE_CLASSES, true);

        if (isset($config['cache']) && $config['cache'] == true) {
            $cacheDriver = new Doctrine_Cache_Apc();
            $manager->setAttribute(Doctrine_Core::ATTR_QUERY_CACHE, $cacheDriver);
        }

        $connection = $manager->openConnection($config['dns'], 'doctrine');
        // telling Doctrine where our models are located
        Doctrine::loadModels(APPLICATION_PATH.'/modules/default/models');

        $connection->setAttribute(Doctrine_Core::ATTR_USE_NATIVE_ENUM, true);
        $connection->setCharset('utf8');

        return $connection;
    }

    protected function _initAutoload()
    {
        $autoloader = new Zend_Application_Module_Autoloader(array(
            'namespace' => 'Default_',
            'basePath'  => APPLICATION_PATH . '/modules/default',
        ));
        $autoloader->addResourceType('Models', 'models', 'Models');
        $autoloader->addResourceType('Forms', 'forms', 'Forms');
        return $autoloader;
    }

}